﻿using System;
using System.Web.Http;
using Newtonsoft.Json;
using Ymatou.API.Common;
using Ymatou.CommonService;
using Ymatou.Evaluate.Seller.Model.ApiModel.Request.Opt;
using Ymatou.Evaluate.Seller.Model.ApiModel.Response.Opt;
using Ymatou.Evaluate.Service.Seller.Implement;
using Ymatou.PerfMonitorClient;

namespace Evaluate.Api.Controllers
{
    public class OperatorController : ApiController
    {
        /// <summary>
        /// 商品评价回复
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("api/opt/EvaluateReply")]
        [HttpPost]
        public BaseResponseModel<EvaluateReplyResponse> EvaluateReply([FromBody]EvaluateReplyRequest request)
        {
            using (MethodMonitor.New("api/opt/EvaluateReply"))
            {
                try
                {
                    if (request == null) throw new BussniessException("-1", "请求参数不能传入null");
                    request.Validate();

                    var response = new SellerOperatorService().AddReply(request);
                    return new SuccessResponseModel<EvaluateReplyResponse>(response);
                }
                catch (BussniessException ex)
                {
                    ApplicationLog.Info(string.Format("api/opt/EvaluateReply业务异常：Code={0},Msg={1}", ex.ErrorCode, ex.ErrorMsg));
                    return new BussniessErrorResponseModel<EvaluateReplyResponse>(int.Parse(ex.ErrorCode), ex.ErrorMsg);
                }
                catch (Exception ex)
                {
                    ApplicationLog.Error("api/opt/EvaluateReply异常", ex);
                    ApplicationLog.Info(string.Format("api/opt/EvaluateReply异常请求参数:{0}", JsonConvert.SerializeObject(request)));
                    return new SystemErrorResponseModel<EvaluateReplyResponse>(ex.Message);
                }
            }
        }
    }
}
